# @Time    :2025/4/8 11:39
import socket

# 创建socket对象
socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
#绑定ip和端口号
socket.bind(("127.0.0.1",8080))
while True:
    # 接收数据
    recv_data, client_info = socket.recvfrom(1024)
    client_ip = client_info[0]
    client_port = client_info[1]

    print(f"服务器{client_info[0]}说：{recv_data.decode('utf-8')}")
    #发送数据
    socket.sendto("你好".encode('utf-8'),client_info)
    # 关闭socket对象
socket.close()